// import router from "@/router"
import Cookie from "js-cookie"

export default{
    state:{
        isCollapse:false,
        mune:[],
    },
    mutations: {
        CollapseMune(state){
            state.isCollapse=!state.isCollapse
        },
        setMune(state,val){
            state.mune=val
            Cookie.set('mune',JSON.stringify(val))
        },
        clearMune(state){
            state.mune=[]
            Cookie.remove('mune')
        },
        addMune(state,router){
     if(!Cookie.get('mune')) {
        return
    }
        const mune=JSON.parse(Cookie.get('mune'))
        state.mune=mune
        const muneArry=[]
        mune.forEach(item => {
            if(item.children){
                item.children=item.children.map(item=>{
                    item.component=()=>import(`@/views/${item.url}`)
                        return item
                    
                })

                muneArry.push(...item.children)
            }
            else{
                item.component=()=>
                    import(`@/views/${item.url}`)
                    muneArry.push(item)
                    
                
            }
           
        });
          // 添加
           
          muneArry.forEach(item=>{
            console.log(router)
     
      router.addRoute('layout',item)
         })
        },
       

    },
}